package com.github.binarywang.utils.qrcode;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 作者：13687
 * 日期：2017/9/24
 * 项目：qrcode-utils
 * 描述：二维码生成器
 */
public class Generator {

	public static void gen800(String content){
		File file =new File(content+"_800.jpg");
		FileOutputStream outputStream = null;
		try {
			outputStream = new FileOutputStream(file);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}

//		加密
		content = EncryptUtil.encrypt(content);
//		生成二维码
		byte[] bytes = QrcodeUtils.createQrcode(content, 800, null);
		try {
			outputStream.write(bytes);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try {
				outputStream.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}


	}

	public static void genOtherSize(String content,int size){
		File file =new File(content+"_"+size+".jpg");
		FileOutputStream fileOutputStream = null;
		try {
			fileOutputStream = new FileOutputStream(file);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}

//		加密
		content = EncryptUtil.encrypt(content);
//		生成二维码
		byte[] bytes = QrcodeUtils.createQrcode(content, size, null);
		try {
			fileOutputStream.write(bytes);
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			try {
				fileOutputStream.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}


	}
}
